﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace hissql
{
    public partial class pat_dayin : Form
    {
        public pat_dayin()
        {
            InitializeComponent();
        }

        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            e.Graphics.DrawString("医院发票", new Font("宋体", 58, FontStyle.Regular), Brushes.Black, 270, 250);
            e.Graphics.DrawString(lb_name.Text, new Font("宋体", 28, FontStyle.Regular), Brushes.Black, 250, 400);
            //绘制textBox1中的内容
            e.Graphics.DrawString(tb_name.Text, new Font("宋体", 28, FontStyle.Regular), Brushes.Black, 370, 400);
            //绘制label3中的内容
            e.Graphics.DrawString(lb_no.Text, new Font("宋体", 28, FontStyle.Regular), Brushes.Black, 250, 450);
            //绘制textBox2中的内容
            e.Graphics.DrawString(tb_no.Text, new Font("宋体", 28, FontStyle.Regular), Brushes.Black, 370, 450);
            //绘制label3中的内容
            e.Graphics.DrawString(lb_yisheng.Text, new Font("宋体", 28, FontStyle.Regular), Brushes.Black, 250, 500);
            //绘制textBox3中的内容
            e.Graphics.DrawString(tb_yisheng.Text, new Font("宋体", 28, FontStyle.Regular), Brushes.Black, 450, 500);
           
            e.Graphics.DrawString(lb_guahao.Text , new Font("宋体", 28, FontStyle.Regular), Brushes.Black, 250, 550);
            //绘制textBox3中的内容
            e.Graphics.DrawString(tb_guahao.Text, new Font("宋体", 28, FontStyle.Regular), Brushes.Black, 500, 550);
           
            e.Graphics.DrawString(lb_menzhen .Text  , new Font("宋体", 28, FontStyle.Regular), Brushes.Black, 250, 600);
            //绘制textBox3中的内容
            e.Graphics.DrawString(tb_menzhen.Text , new Font("宋体", 28, FontStyle.Regular), Brushes.Black, 500, 600);
           
            e.Graphics.DrawString(lb_yaofei.Text   , new Font("宋体", 28, FontStyle.Regular), Brushes.Black, 250, 650);
            //绘制textBox3中的内容
            e.Graphics.DrawString(tb_yaofei.Text, new Font("宋体", 28, FontStyle.Regular), Brushes.Black, 500, 650);


            e.Graphics.DrawString(lb_heji .Text , new Font("宋体", 28, FontStyle.Regular), Brushes.Black, 250, 700);
            //绘制textBox3中的内容
            e.Graphics.DrawString(tb_heji .Text , new Font("宋体", 28, FontStyle.Regular), Brushes.Black, 500, 700);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            printDialog1.ShowDialog();                               //用默认的所有者使用通用对话框
            printPreviewDialog1.Document = this.printDocument1;      //设置打印文档
            printPreviewDialog1.ShowDialog();       
        }

        private void lb_heji_Click(object sender, EventArgs e)
        {

        }

        private void pat_dayin_Load(object sender, EventArgs e)
        {
           
            tb_guahao.Text = "10";
            tb_menzhen.Text = "15";


            SqlCommand sqlCommand = new SqlCommand();                                       //声明并实例化SQL命令；
            sqlCommand.Connection = sqlHelper.sqlConnection;                                          //将SQL命令的属性Connection指向SQL连接；
            sqlCommand.CommandText =                                                        //指定SQL命令的命令文本；命令文本由字符串拼接而成；
                "SELECT SUM(Price) FROM tb_PM where PatientNo='" + UserHelper.No + "'";
            sqlHelper.sqlConnection.Open();                                                           //打开SQL连接；
            tb_yaofei.Text = Convert.ToString(sqlCommand.ExecuteScalar());                                 //调用SQL命令的方法ExecuteScalar来执行命令，并接受单个结果（即标量）；

            float a = Convert.ToSingle(tb_yaofei.Text) + 25;
            tb_heji.Text = Convert .ToString(a) ;
            sqlHelper.sqlConnection.Close();

            tb_name.Text = UserHelper.name;
            tb_no.Text = UserHelper.No;

            SqlCommand sqlCommand1 = new SqlCommand();                                       //声明并实例化SQL命令；
            sqlCommand1.Connection = sqlHelper.sqlConnection;
            sqlCommand1.CommandText =                                                        //指定SQL命令的命令文本；命令文本由字符串拼接而成；
               "SELECT DoctorName FROM tb_Invoice where PatientNo='" + UserHelper.No + "'";
                                                                   //打开SQL连接；
            sqlHelper.sqlConnection.Open();     
            tb_yisheng.Text = Convert.ToString(sqlCommand1.ExecuteScalar());                                 //调用SQL命令的方法ExecuteScalar来执行命令，并接受单个结果（即标量）；
            
           
            sqlHelper.sqlConnection.Close();

        }
    }
}
